package com.hsteach.web.controller.patrol;

import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.exception.ServiceException;
import com.hsteach.service.patrol.BaseRuleService;
import com.hsteach.web.controller.patrol.dto.BaseConfigDTO;
import com.hsteach.web.controller.visit.vo.RuleDescriptionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *
 * </p>
 *
 * @author mgb
 * @version PatrolBaseRuleController, java v1.0 2023-11-08 21:43 EXP $
 */
@Api(value = "评分规则设置", tags = "评分规则设置")
@RestController
@RequestMapping("/patrol/base")
public class PatrolBaseRuleController extends BaseController {

    @Autowired
    public BaseRuleService baseRuleService;

    @ApiOperation("查询所有规则配置")
    @GetMapping("/queryBaseConfig")
    public AjaxResult queryBaseConfig(String orgCode) {
        return success(baseRuleService.queryBaseConfig(orgCode));
    }

    @ApiOperation("修改基础参数设置设置")
    @PostMapping("/updateBaseInfo")
    public AjaxResult updateBaseInfo(@RequestBody BaseConfigDTO baseConfigDTO) {
        return success("保存成功",baseRuleService.updateBaseInfo(baseConfigDTO));
    }


    @ApiOperation("增加规则说明")
    @PostMapping("/addRuleDesc")
    public AjaxResult addRuleDesc(@RequestParam(name = "ruleDesc") String ruleDesc,
                                  @RequestParam(name = "ruleName") String ruleName,
                                  @RequestParam(name = "orgCode") String orgCode) {
        if (StringUtils.isEmpty(orgCode)){
            throw new ServiceException("orgCode不能为空");
        }
        if (StringUtils.isEmpty(ruleName)) {
            throw new ServiceException("ruleName不能为空");
        }
        return success("添加成功",baseRuleService.addRuleDesc(ruleName, ruleDesc,orgCode));
    }

    @ApiOperation("规则说明修改")
    @PostMapping("/updateRuleDesc")
    public AjaxResult updateRuleDesc(@RequestBody RuleDescriptionVO ruleDescriptionVO) {
        return success("保存成功",baseRuleService.updateRuleDesc(ruleDescriptionVO));
    }
    @ApiOperation("规则说明列表")
    @PostMapping("/queryRuleDesc")
    public AjaxResult queryRuleDesc(String orgCode) {

        return success(baseRuleService.queryRuleDesc(orgCode));
    }

    @ApiOperation("规则说明")
    @GetMapping("/getRuleDesc")
    public AjaxResult getRuleDesc(@RequestParam(name = "ruleName") String ruleName,
                                  @RequestParam(name = "orgCode") String orgCode) {
        if (StringUtils.isEmpty(orgCode)){
            throw new ServiceException("orgCode不能为空");
        }
        return success(baseRuleService.getRuleDescById(ruleName,orgCode));
    }

}
